package com.barbeque.mall.controller.wx;

import com.barbeque.mall.bean.BaseRespVo;
import com.barbeque.mall.bean.category.MarketCategory;
import com.barbeque.mall.bean.wx.catalog.WxMarketCatalogIndexVO;
import com.barbeque.mall.bean.wx.catalog.WxMarketCatalogVO;
import com.barbeque.mall.service.wx.WxCatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 苏东宇
 * @since 2022/07/19 23:09
 */
@RestController
@RequestMapping("wx/catalog")
public class WxCatalogController {

    @Autowired
    WxCatalogService wxCatalogService;


    @RequestMapping("current")
    public BaseRespVo getCurrentCatalog(Integer id){
        WxMarketCatalogVO wxMarketCatalogVO = new WxMarketCatalogVO();

        //先根据id查询当前的品类
        MarketCategory currentCategory = wxCatalogService.getCatalogById(id);
        //查询以当前品类id作为pid的所有品类
        List<MarketCategory> catalogByPid = wxCatalogService.getCatalogByPid(id);

        wxMarketCatalogVO.setCurrentCategory(currentCategory);
        wxMarketCatalogVO.setCurrentSubCategory(catalogByPid);

        return BaseRespVo.ok(wxMarketCatalogVO);

    }


    @RequestMapping("index")
    public BaseRespVo getIndexCatalog(){
        WxMarketCatalogIndexVO wxMarketCatalogIndexVO = new WxMarketCatalogIndexVO();

        //查询所有主类目
        List<MarketCategory> catalogByPid = wxCatalogService.getCatalogByPid(0);
        //选择一个主类目
        MarketCategory marketCategory = catalogByPid.get(0);
        //查询以当前品类id作为pid的所有zi品类
        List<MarketCategory> subCatalog = wxCatalogService.getCatalogByPid(marketCategory.getId());

        wxMarketCatalogIndexVO.setCurrentCategory(marketCategory);
        wxMarketCatalogIndexVO.setCategoryList(catalogByPid);
        wxMarketCatalogIndexVO.setCurrentSubCategory(subCatalog);

        return BaseRespVo.ok(wxMarketCatalogIndexVO);

    }
}
